Add _gtk_toolbar_paint_space_line(), _gtk_toolbar_get_default_space_size
authorSoeren Sandmann <sandmann@daimi.au.dk>
Sun, 18 Jan 2004 14:31:00 +0000 (14:31 +0000)
committerSøren Sandmann Pedersen <ssp@src.gnome.org>
Sun, 18 Jan 2004 14:31:00 +0000 (14:31 +0000)
Sun Jan 18 15:25:39 2004  Soeren Sandmann  <sandmann@daimi.au.dk>

* gtk/gtktoolbar.[ch]: Add _gtk_toolbar_paint_space_line(),
_gtk_toolbar_get_default_space_size ();

* gtk/gtkseparatortoolitem.c (gtk_separator_tool_item_expose,
get_space_size): Use them here.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkseparatortoolitem.c
gtk/gtktoolbar.c
gtk/gtktoolbar.h

index 84b7ae85e24b5857c5c28d97699e22ce719b07b2..eedd52a214aa327498705e346e0e3a9134ac951e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sun Jan 18 15:25:39 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.[ch]: Add _gtk_toolbar_paint_space_line(),
+       _gtk_toolbar_get_default_space_size ();
+
+       * gtk/gtkseparatortoolitem.c (gtk_separator_tool_item_expose,
+       get_space_size): Use them here.
+
 Sun Jan 18 13:16:34 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
 
        * tests/testgtk.c (create_toolbar): Set a small size request and
index 84b7ae85e24b5857c5c28d97699e22ce719b07b2..eedd52a214aa327498705e346e0e3a9134ac951e 100644 (file)
@@ -1,3 +1,11 @@
+Sun Jan 18 15:25:39 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.[ch]: Add _gtk_toolbar_paint_space_line(),
+       _gtk_toolbar_get_default_space_size ();
+
+       * gtk/gtkseparatortoolitem.c (gtk_separator_tool_item_expose,
+       get_space_size): Use them here.
+
 Sun Jan 18 13:16:34 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
 
        * tests/testgtk.c (create_toolbar): Set a small size request and
index 84b7ae85e24b5857c5c28d97699e22ce719b07b2..eedd52a214aa327498705e346e0e3a9134ac951e 100644 (file)
@@ -1,3 +1,11 @@
+Sun Jan 18 15:25:39 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.[ch]: Add _gtk_toolbar_paint_space_line(),
+       _gtk_toolbar_get_default_space_size ();
+
+       * gtk/gtkseparatortoolitem.c (gtk_separator_tool_item_expose,
+       get_space_size): Use them here.
+
 Sun Jan 18 13:16:34 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
 
        * tests/testgtk.c (create_toolbar): Set a small size request and
index 84b7ae85e24b5857c5c28d97699e22ce719b07b2..eedd52a214aa327498705e346e0e3a9134ac951e 100644 (file)
@@ -1,3 +1,11 @@
+Sun Jan 18 15:25:39 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.[ch]: Add _gtk_toolbar_paint_space_line(),
+       _gtk_toolbar_get_default_space_size ();
+
+       * gtk/gtkseparatortoolitem.c (gtk_separator_tool_item_expose,
+       get_space_size): Use them here.
+
 Sun Jan 18 13:16:34 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
 
        * tests/testgtk.c (create_toolbar): Set a small size request and
index 84b7ae85e24b5857c5c28d97699e22ce719b07b2..eedd52a214aa327498705e346e0e3a9134ac951e 100644 (file)
@@ -1,3 +1,11 @@
+Sun Jan 18 15:25:39 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.[ch]: Add _gtk_toolbar_paint_space_line(),
+       _gtk_toolbar_get_default_space_size ();
+
+       * gtk/gtkseparatortoolitem.c (gtk_separator_tool_item_expose,
+       get_space_size): Use them here.
+
 Sun Jan 18 13:16:34 2004  Soeren Sandmann  <sandmann@daimi.au.dk>
 
        * tests/testgtk.c (create_toolbar): Set a small size request and
index 4c37597ca7bb09f06328d22bc5e8cbc5485114af..9986a3057317cea1250dcc6c69399244166616d8 100644 (file)
 #include "gtkintl.h"
 #include "gtktoolbar.h"
 
-/* note: keep in sync with DEFAULT_SPACE_SIZE and DEFAULT_SPACE_STYLE in gtktoolbar.c */
-#define DEFAULT_SPACE_SIZE 4
-#define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
-
-#define SPACE_LINE_DIVISION 10
-#define SPACE_LINE_START    3
-#define SPACE_LINE_END      7
-
 #define MENU_ID "gtk-separator-tool-item-menu-id"
 
 enum {
@@ -59,8 +51,7 @@ static gboolean gtk_separator_tool_item_expose            (GtkWidget
                                                           GdkEventExpose            *event);
 static void     gtk_separator_tool_item_add               (GtkContainer              *container,
                                                           GtkWidget                 *child);
-static GtkToolbarSpaceStyle get_space_style               (GtkToolItem               *tool_item);
-static gint                 get_space_size                (GtkToolItem               *tool_item);
+static gint     get_space_size                            (GtkToolItem               *tool_item);
 
 
 
@@ -99,26 +90,10 @@ gtk_separator_tool_item_get_type (void)
   return type;
 }
 
-static GtkToolbarSpaceStyle
-get_space_style (GtkToolItem *tool_item)
-{
-  GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
-  GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
-  
-  if (GTK_IS_TOOLBAR (parent))
-    {
-      gtk_widget_style_get (parent,
-                           "space_style", &space_style,
-                           NULL);
-    }
-  
-  return space_style;  
-}
-
 static gint
 get_space_size (GtkToolItem *tool_item)
 {
-  gint space_size = DEFAULT_SPACE_SIZE;
+  gint space_size = _gtk_toolbar_get_default_space_size();
   GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
   
   if (GTK_IS_TOOLBAR (parent))
@@ -176,7 +151,7 @@ static void
 gtk_separator_tool_item_add (GtkContainer *container,
                             GtkWidget    *child)
 {
-  g_warning("attempt to add a child to an GtkSeparatorToolItem");
+  g_warning ("attempt to add a child to an GtkSeparatorToolItem");
 }
 
 static gboolean
@@ -252,44 +227,13 @@ static gboolean
 gtk_separator_tool_item_expose (GtkWidget      *widget,
                                GdkEventExpose *event)
 {
-  GtkToolItem *tool_item = GTK_TOOL_ITEM (widget);
-  GtkSeparatorToolItem *separator_tool_item = GTK_SEPARATOR_TOOL_ITEM (widget);
-  gint space_size;
-  GtkAllocation *allocation;
-  GtkOrientation orientation;
-  GdkRectangle *area;
+  GtkToolbar *toolbar = NULL;
 
-  if (separator_tool_item->priv->draw &&
-      get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE)
-    {
-      space_size = get_space_size (tool_item);
-      allocation = &(widget->allocation);
-      orientation = gtk_tool_item_get_orientation (tool_item);
-      area = &(event->area);
-      
-      if (orientation == GTK_ORIENTATION_HORIZONTAL)
-       {
-         gtk_paint_vline (widget->style, widget->window,
-                          GTK_WIDGET_STATE (widget), area, widget,
-                          "separator_tool_item",
-                          allocation->y + allocation->height *
-                          SPACE_LINE_START / SPACE_LINE_DIVISION,
-                          allocation->y + allocation->height *
-                          SPACE_LINE_END / SPACE_LINE_DIVISION,
-                          allocation->x + (space_size - widget->style->xthickness) / 2);
-       }
-      else if (orientation == GTK_ORIENTATION_VERTICAL)
-       {
-         gtk_paint_hline (widget->style, widget->window,
-                          GTK_WIDGET_STATE (widget), area, widget,
-                          "separator_tool_item",
-                          allocation->x + allocation->width *
-                          SPACE_LINE_START / SPACE_LINE_DIVISION,
-                          allocation->x + allocation->width *
-                          SPACE_LINE_END / SPACE_LINE_DIVISION,
-                          allocation->y + (space_size - widget->style->ythickness) / 2);
-       }
-    }
+  if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
+    toolbar = GTK_TOOLBAR (widget->parent);
+
+  _gtk_toolbar_paint_space_line (widget, toolbar,
+                                &(event->area), &widget->allocation);
   
   return FALSE;
 }
index 689025fc3616b2eb8a0f2f4b07f2c58b51e40b32..39a4a0bb1a615cf2fbebc4402578b928447ca6f0 100644 (file)
@@ -58,9 +58,9 @@ typedef struct _ToolbarContent ToolbarContent;
 /* note: keep in sync with DEFAULT_SPACE_SIZE and DEFAULT_SPACE_STYLE in gtkseparatortoolitem.c */
 #define DEFAULT_SPACE_SIZE  4
 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
-#define SPACE_LINE_DIVISION 10
-#define SPACE_LINE_START    3
-#define SPACE_LINE_END      7
+#define SPACE_LINE_DIVISION 10.0
+#define SPACE_LINE_START    3.0
+#define SPACE_LINE_END      7.0
 
 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
@@ -3631,7 +3631,13 @@ toolbar_content_new_tool_item (GtkToolbar  *toolbar,
   priv->content = g_list_insert (priv->content, content, pos);
   
   if (!is_placeholder)
-    toolbar->num_children++;
+    {
+      toolbar->num_children++;
+
+      gtk_toolbar_stop_sliding (toolbar);
+    }
+
+  gtk_widget_queue_resize (GTK_WIDGET (toolbar));
   
   return content;
 }
@@ -3744,24 +3750,32 @@ calculate_max_homogeneous_pixels (GtkWidget *widget)
   return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
 }
 
-static void
-gtk_toolbar_paint_space_line (GtkWidget       *widget,
-                             GdkRectangle    *area,
-                             ToolbarContent  *content)
+gint
+_gtk_toolbar_get_default_space_size (void)
 {
-  GtkToolbar *toolbar;
-  gint space_size;
-  GtkAllocation *allocation = &(content->u.compatibility.space_allocation);
-  double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
-  double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
-  
-  g_return_if_fail (GTK_IS_TOOLBAR (widget));
+  return DEFAULT_SPACE_SIZE;
+}
+
+void
+_gtk_toolbar_paint_space_line (GtkWidget       *widget,
+                              GtkToolbar      *toolbar,
+                              GdkRectangle    *area,
+                              GtkAllocation   *allocation)
+{
+  const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
+  const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
   
-  toolbar = GTK_TOOLBAR (widget);
+  gint space_size;
+  GtkToolbarSpaceStyle space_style;
+  GtkOrientation orientation;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
   
   space_size = get_space_size (toolbar);
-  
-  if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+  space_style = get_space_style (toolbar);
+  orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
+
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       gtk_paint_vline (widget->style, widget->window,
                       GTK_WIDGET_STATE (widget), area, widget,
@@ -3805,7 +3819,9 @@ toolbar_content_expose (ToolbarContent *content,
          if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE &&
              content->u.compatibility.space_visible)
            {
-             gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), &expose->area, content);
+             _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
+                                            &expose->area,
+                                            &content->u.compatibility.space_allocation);
            }
          return;
        }
@@ -4409,9 +4425,12 @@ get_space_size (GtkToolbar *toolbar)
 {
   gint space_size = DEFAULT_SPACE_SIZE;
   
-  gtk_widget_style_get (GTK_WIDGET (toolbar),
-                        "space_size", &space_size,
-                        NULL);
+  if (toolbar)
+    {
+      gtk_widget_style_get (GTK_WIDGET (toolbar),
+                           "space_size", &space_size,
+                           NULL);
+    }
   
   return space_size;
 }
@@ -4420,11 +4439,13 @@ static GtkToolbarSpaceStyle
 get_space_style (GtkToolbar *toolbar)
 {
   GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
-  
-  gtk_widget_style_get (GTK_WIDGET (toolbar),
-                        "space_style", &space_style,
-                        NULL);
-  
+
+  if (toolbar)
+    {
+      gtk_widget_style_get (GTK_WIDGET (toolbar),
+                           "space_style", &space_style,
+                           NULL);
+    }
   
   return space_style;  
 }
index a7fa7bdc7678d5a1cb942f82470f50ca3b3dadec..693d2a7af403026a84a4e5fcd593421fcfac5f08 100644 (file)
@@ -167,11 +167,11 @@ void            gtk_toolbar_set_drop_highlight_item   (GtkToolbar      *toolbar,
 
 /* internal functions */
 gchar *                     _gtk_toolbar_elide_underscores (const gchar *original);
-/* these two functions actually accept NULL for the toolbar, in which case
- * you'll get a default value
- */
-int                 _gtk_toolbar_get_space_size    (GtkToolbar *toolbar);
-GtkToolbarSpaceStyle _gtk_toolbar_get_space_style   (GtkToolbar *toolbar);
+void                 _gtk_toolbar_paint_space_line (GtkWidget       *widget,
+                                                   GtkToolbar      *toolbar,
+                                                   GdkRectangle    *area,
+                                                   GtkAllocation   *allocation);
+gint                 _gtk_toolbar_get_default_space_size (void);
 
 #ifndef GTK_DISABLE_DEPRECATED
 void       gtk_toolbar_set_icon_size   (GtkToolbar      *toolbar,